home *** CD-ROM | disk | FTP | other *** search
- // Assignment 5
-
- #include "SAT.h"
-
- short kSpeed = 5;
- SpritePtr ignore;
- short direction;
- Handle theSound;
-
- pascal void SetupTarget (SpritePtr me);
-
- pascal void HandleSprite (SpritePtr me)
- {
- GetMouse(&me->position);
- }
-
- pascal void SetupSprite (SpritePtr me)
- {
- me->task = &HandleSprite;
- me->face = SATGetFace(128);
- SetRect(&me->hotRect, 0, 0, 32, 32);
- }
-
- pascal void HandleTarget (SpritePtr me)
- {
- me->position.h = me->position.h + direction;
- if (me->position.h < 0)
- direction = kSpeed;
- if (me->position.h > 200)
- direction = -kSpeed;
-
- if (me->kind != -1) // Hit Me!
- {
- me->task = 0L;
- ignore = SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), &SetupTarget);
-
- // We could also re-use the old sprite for a new one, if we like.}
-
- SATSoundPlay(theSound, 1, true);
- }
- }
-
- pascal void SetupTarget (SpritePtr me)
- {
- me->task = &HandleTarget;
- me->face = SATGetFace(129);
- SetRect(&me->hotRect, 0, 0, 32, 32);
- direction = kSpeed;
- }
-
- main()
- {
- short kTicksPerFrame = 2;
- long t;
-
- SATInitToolbox();
- SATInit(128, 129, 478, 302);
- ignore = SATNewSprite(1, 200, 200, &SetupSprite);
- ignore = SATNewSprite(-1, 0, SATRand(gSAT.offSizeV), &SetupTarget);
- theSound = SATGetNamedSound("\pTestSound");
- HideCursor();
- do
- {
- t = TickCount();
- SATRun(true);
- while ((TickCount () - t) < kTicksPerFrame);
- } while (! Button());
- ShowCursor();
- SATSoundShutup();
- }
-